package com.ysy.logistics.controller.supplier;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ysy.common.resp.ResultData;
import com.ysy.logistics.entities.supplier.SupOrder;
import com.ysy.logistics.entities.supplier.dto.SupOrderDto;
import com.ysy.logistics.entities.supplier.vo.SupplierQueryVO;
import com.ysy.logistics.myannotation.OperateLog;
import com.ysy.logistics.service.supplier.SupOrderService;
import com.ysy.logistics.util.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassDescription:
 * @Author:姚斯羽
 * @Create:2025/3/29 22:25
 **/
@Slf4j
@RestController
@RequestMapping(value = "/supOrder",name = "采购管理")
@Tag(name = "采购管理",description = "supOrder表的CRUD")
@CrossOrigin
public class SupOrderController {

    @Resource
    private SupOrderService supOrderService;

    @PostMapping("/listByPage")
    @Operation(summary = "分页查询",description = "分页查询")
    @OperateLog(value = "采购单查询")
    public ResultData listByPage(@RequestBody PageInfo<SupOrder> pageInfo){
        log.debug("分页查询采购单："+pageInfo);
       return ResultData.success( supOrderService.listByPage(pageInfo));
    }

    @PostMapping("/save")
    @Operation(summary = "保存订单",description = "保存订单")
    @OperateLog(value = "新增采购")
    public ResultData save(@RequestBody SupOrderDto supOrderDto){
        return supOrderService.saveSupOrderDto(supOrderDto);
    }

    @GetMapping("/getGoodsListByOrderId/{id}")
    @Operation(summary = "根据订单id查询商品",description = "根据订单id查询商品")
    public ResultData getGoodsListByOrderId(@PathVariable("id") String id){
        return ResultData.success(supOrderService.getGoodsListByOrderId(id));
    }

    @GetMapping("/backOrder/{id}")
    @Operation(summary = "退货",description = "退货")
    @OperateLog(value = "采购单退货")
    public ResultData backOrder(@PathVariable("id") String id){
        return ResultData.success(supOrderService.backOrder(id));
    }

    @GetMapping("/flushOrderStatus")
    @Operation(summary = "刷新订单状态",description = "刷新订单状态")
    @OperateLog(value = "刷新订单状态")
    public ResultData flushOrderStatus(){
        return ResultData.success(supOrderService.flushOrderStatus());
    }
}
